<?php
include_once 'fun.php';
include_once 'islogin.php';
    //var_dump($_POST);
    $_SESSION['isadmin']=isset($_SESSION['isadmin'])?$_SESSION['isadmin']:'';
    if ($_SESSION['isadmin']!=3&&$_SESSION['isadmin']!=-1) {
        header('Refresh:1;url=shop.php');
        die("请以人力管理员身份登录");
    }
    $Name = trim($_POST['Name']);
    $age = isset($_POST['age'])?$_POST['age']:'';
    $gender =($_POST['gender']=='男')?1:0;
    $manager  = isset($_POST['manager'])?$_POST['manager']:'';
    $xingbie  = isset($_POST['xingbie'])?$_POST['xingbie']:'';
   
    $id=(int)$_POST['id'];
    $userid=(int)$_POST['userid'];
    if(empty($Name))
    {
    header('Refresh:0;url=stuff.php');
    die("姓名不能为空");
    }
    
    else
    {
        if($xingbie!='')
        $gender=$xingbie;
        $con=connect();
        if($manager!='')
        $sql = "update stuff set Name='{$Name}',age='{$age}',gender={$gender},managerid={$manager} where stuffid={$id};";
        else
        $sql = "update stuff set Name='{$Name}',age='{$age}',gender={$gender} where stuffid={$id};";
        
        query($sql,$con);
        $sql="update user set username='{$Name}' where id=$userid;";
        query($sql,$con);
        echo '保存成功';
        
   header('Refresh:0;url=stuff.php');
    
    }
    
    
?>